<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <h3>
            Mockjs
        </h3>
        <div v-for="item in list">
            {{ item.title }}
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/Mock.js/1.0.1-beta3/mock-min.js"></script>

    <script>
        //  Mock.mock(接口地址, 请求方式, 响应的内容)
        Mock.mock("/getList", {
            // 模拟数量
            "list|10-20": [
                {
                    // id自增
                    "id|+1": 1,
                    // 随机名字
                    name: "@cname",
                    // 随机价格
                    "price|10-20": 10,
                    title: "@ctitle",
                    img: "@Image(100)",
                    address: "@city"
                }
            ]
        })

        const app = new Vue({
            el: "#app",
            data: {
                list: [],
                obj: {
                    name: "张三"
                }
            },
            created() {
                console.log(this.obj)
                axios.get("/getList").then(res => {
                    this.list = res.data.list
                    console.log(res.data)
                })
            }
        })


    </script>
</body>

</html>